package com.jetpack.mvvm.lib.net.interceptor

import com.jetpack.mvvm.lib.common.ext.logV
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

/**
 *  author: wangyb
 *  date: 2021/5/28 10:19 上午
 *  description: todo
 */
class LoggingInterceptor : Interceptor {

    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val t1 = System.nanoTime()
//        logV("Sending request: ${request.url} \n ${request.headers}", null)
        println("Sending request: ${request.url} \n ${request.headers}")

        val response = chain.proceed(request)

        val t2 = System.nanoTime()
//        logV("Received response for  ${response.request.url} in ${(t2 - t1) / 1e6} ms \n ${response.headers}", null)
        println("Received response for  ${response.request.url} in ${(t2 - t1) / 1e6} ms}")
        return response
    }

    companion object {
        const val TAG = "LoggingInterceptor"
    }
}